package timbap.visualizer.coreplugins;

import timbap.visualizer.api.model.PlaylistEntry;
import timbap.visualizer.api.plugin.poscloud.AbstractPosCloudPlugin;

import java.util.Comparator;

public class ArtistNameInitialsPosCloudPlugin extends AbstractPosCloudPlugin<Character> {
    
    private static Comparator<PlaylistEntry> playlistEntryComparator;

    @Override
    public void drawPosCloudElement(Character posCloudElement, boolean pIsSelected) {
    	if (pIsSelected) {
    		getContext().getP5Applet().fill(255,200,200);
    	} else {
    		getContext().getP5Applet().fill(155,100,100);
    	}
    	getContext().getP5Applet().text(posCloudElement.toString(), 0, 0, 100, 100, 5);
    }

    @Override
    public Character createPosCloudElement(PlaylistEntry pPlaylistEntry) {
    	String tArtistName = pPlaylistEntry.getArtistName();
    	if (tArtistName != null && tArtistName.length() > 0) {
    		return tArtistName.toUpperCase().charAt(0);
    	} else {
    		return ' ';
    	}
    }

    public Comparator<PlaylistEntry> getPlaylistEntryComparator() {
        if (playlistEntryComparator == null) {
            playlistEntryComparator = new Comparator<PlaylistEntry>() {

                public int compare(PlaylistEntry pEntry, PlaylistEntry pCompareEntry) {
                    return pEntry.getArtistName().compareTo(pCompareEntry.getArtistName());
                }
                
            };
        }
        return playlistEntryComparator;
    }
    
    
}
